<?php
/**
 * Created by PhpStorm.
 * User: xiaofeng
 * motto: 现在的努力是为了小时候吹过的牛逼！
 * Date: 2020/9/17
 * Time: 22:11
 */
namespace app\admin\controller;
use app\common\business\Goods as GoodsBis;
class Goods extends AdminBase {
    public function index(){
        $data = [];
        $title = input("param.title","","trim");
        $time = input("param.time","","trim");

        if (!empty($title)){
            $data['title'] = $title;
        }
        if (!empty($time)){
            $data['create_time'] = explode("-",$time);
        }

        $goods = (new GoodsBis())->getList($data,5);

        return view("",[
            "goods"=>$goods
        ]);

    }
    public function add(){

        return view();

    }

    public function save(){
        // 判断是否为post请求，也可以通过在路由中做配置支持post即可
        if (!$this->request->isPost()){
            return show(config("status.error"),"参数不合法");
        }
        $data = input("param.");
       //halt($data);
        $check = $this->request->checkToken('__token__',$data);
        if (!$check){
            return show(config('status.error'),"非法请求");
        }
        // 数据处理=》基于验证成功之后
        $data['category_path_id'] = $data['category_id'];
        $result = explode(",",$data['category_path_id']);
        $data['category_id'] = end($result);
        $res = (new GoodsBis())->insertData($data);
        if (!$res){
            return show(config("status.error"),"商品新增失败");
        }
        return show(config("status.success"),"商品新增成功");
    }
}
